package com.leilei.sink;

import java.nio.charset.StandardCharsets;
import java.time.LocalDate;

/**
 * @author lei
 * @version 1.0
 * @desc
 * @date 2021-03-15 16:46
 */
public class OverSpeedAlarmSinkFunction extends DataRichSinkFunction<String> {

    public OverSpeedAlarmSinkFunction(RabbitMqSinkProperties rabbitMQSinkProperties) {
        /**
         * 调用父类（DataRichSinkFunction）属性填充
         */
        super(rabbitMQSinkProperties);
    }

    /**
     * 数据输出到 rabbitMQSinkProperties 指定的交换机中
     * @param value
     * @param context
     * @throws Exception
     */
    @Override
    public void invoke(String value, Context context) throws Exception {
        System.out.println(LocalDate.now() + "发送数据：" + value);
        channel.basicPublish(rabbitMQSinkProperties.getExchange(), "", null, value.getBytes(StandardCharsets.UTF_8));
    }
}
